'use strict';
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async (event, context) => {
	
	const{
		user_id,
		acticle_id
	} = event
	
	const userinfo = await db.collection('users').doc(user_id).get()
	const likes_ids = userinfo.data[0].likes_ids
	let dbCmdFuns = null
	if (likes_ids.includes(acticle_id)) {
		dbCmdFuns = dbCmd.pull(acticle_id)
	} else {
		dbCmdFuns = dbCmd.addToSet(acticle_id)
	}
	
	await db.collection('users').doc(user_id).update({
		likes_ids: dbCmdFuns
	})
	
	//返回数据给客户端
	return {
		code: 200,
		message: "数据请求成功",
		data: userinfo.data[0]
	}
};
